using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VLRFKORR
    {
        public DataRow Convert2LRFKORR(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryLRFKORR(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["LRFMANDANT"] = " ".PadRight(2 ); 
         dwReturn["LRFKORRTAB"] = " ".PadRight(8 ); 
         dwReturn["LRFMAT"] = " ".PadRight(14 ); 
         dwReturn["LRFKORRFAKT"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR1"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH1"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR2"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH2"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR3"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH3"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR4"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH4"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR5"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH5"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR6"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH6"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR7"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH7"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR8"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH8"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR9"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH9"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR10"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH10"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR11"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH11"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR12"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH12"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR13"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH13"] = " ".PadRight(0 ); 
         dwReturn["LRFFAKTOR14"] = " ".PadRight(0 ); 
         dwReturn["LRFFLOTVH14"] = " ".PadRight(0 ); 
         dwReturn["LRFFILLER"] = " ".PadRight(70 ); 
         dwReturn["LRFAENDZL"] = " ".PadRight(0 ); 
         dwReturn["LRFAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["LRFAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["LRFNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["LRFNEUDAT"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapLRFKORR(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLRFKORR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryLRFKORR(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapLRFKORR(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertLRFKORR(dwLocal, ITXDBVERSION);
            }
            UpdateLRFKORR(dwLocal);
        }
        public void InsertLRFKORR(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO LRFKORR(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryLRFKORR(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM LRFKORR WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM LRFKORR  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "LRFKORR";
            Return = Result;
            return Return;
        }
        public void DeleteLRFKORR(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM LRFKORR   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateLRFKORR(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE LRFKORR SET "
                    +"LRFMANDANT= :LRFMANDANT,"
                    +"LRFKORRTAB= :LRFKORRTAB,"
                    +"LRFMAT= :LRFMAT,"
                    +"LRFKORRFAKT= :LRFKORRFAKT,"
                    +"LRFFAKTOR1= :LRFFAKTOR1,"
                    +"LRFFLOTVH1= :LRFFLOTVH1,"
                    +"LRFFAKTOR2= :LRFFAKTOR2,"
                    +"LRFFLOTVH2= :LRFFLOTVH2,"
                    +"LRFFAKTOR3= :LRFFAKTOR3,"
                    +"LRFFLOTVH3= :LRFFLOTVH3,"
                    +"LRFFAKTOR4= :LRFFAKTOR4,"
                    +"LRFFLOTVH4= :LRFFLOTVH4,"
                    +"LRFFAKTOR5= :LRFFAKTOR5,"
                    +"LRFFLOTVH5= :LRFFLOTVH5,"
                    +"LRFFAKTOR6= :LRFFAKTOR6,"
                    +"LRFFLOTVH6= :LRFFLOTVH6,"
                    +"LRFFAKTOR7= :LRFFAKTOR7,"
                    +"LRFFLOTVH7= :LRFFLOTVH7,"
                    +"LRFFAKTOR8= :LRFFAKTOR8,"
                    +"LRFFLOTVH8= :LRFFLOTVH8,"
                    +"LRFFAKTOR9= :LRFFAKTOR9,"
                    +"LRFFLOTVH9= :LRFFLOTVH9,"
                    +"LRFFAKTOR10= :LRFFAKTOR10,"
                    +"LRFFLOTVH10= :LRFFLOTVH10,"
                    +"LRFFAKTOR11= :LRFFAKTOR11,"
                    +"LRFFLOTVH11= :LRFFLOTVH11,"
                    +"LRFFAKTOR12= :LRFFAKTOR12,"
                    +"LRFFLOTVH12= :LRFFLOTVH12,"
                    +"LRFFAKTOR13= :LRFFAKTOR13,"
                    +"LRFFLOTVH13= :LRFFLOTVH13,"
                    +"LRFFAKTOR14= :LRFFAKTOR14,"
                    +"LRFFLOTVH14= :LRFFLOTVH14,"
                    +"LRFFILLER= :LRFFILLER,"
                    +"LRFAENDZL= :LRFAENDZL,"
                    +"LRFAENDBEN= :LRFAENDBEN,"
                    +"LRFAENDDAT= :LRFAENDDAT,"
                    +"LRFNEUBEN= :LRFNEUBEN,"
                    +"LRFNEUDAT= :LRFNEUDAT,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("LRFMANDANT", OracleType.NVarChar).Value = dwData["LRFMANDANT"].ToString(); 
          or1.Parameters.Add("LRFKORRTAB", OracleType.NVarChar).Value = dwData["LRFKORRTAB"].ToString(); 
          or1.Parameters.Add("LRFMAT", OracleType.NVarChar).Value = dwData["LRFMAT"].ToString(); 
          or1.Parameters.Add("LRFKORRFAKT", OracleType.NVarChar).Value = dwData["LRFKORRFAKT"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR1", OracleType.NVarChar).Value = dwData["LRFFAKTOR1"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH1", OracleType.NVarChar).Value = dwData["LRFFLOTVH1"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR2", OracleType.NVarChar).Value = dwData["LRFFAKTOR2"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH2", OracleType.NVarChar).Value = dwData["LRFFLOTVH2"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR3", OracleType.NVarChar).Value = dwData["LRFFAKTOR3"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH3", OracleType.NVarChar).Value = dwData["LRFFLOTVH3"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR4", OracleType.NVarChar).Value = dwData["LRFFAKTOR4"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH4", OracleType.NVarChar).Value = dwData["LRFFLOTVH4"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR5", OracleType.NVarChar).Value = dwData["LRFFAKTOR5"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH5", OracleType.NVarChar).Value = dwData["LRFFLOTVH5"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR6", OracleType.NVarChar).Value = dwData["LRFFAKTOR6"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH6", OracleType.NVarChar).Value = dwData["LRFFLOTVH6"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR7", OracleType.NVarChar).Value = dwData["LRFFAKTOR7"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH7", OracleType.NVarChar).Value = dwData["LRFFLOTVH7"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR8", OracleType.NVarChar).Value = dwData["LRFFAKTOR8"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH8", OracleType.NVarChar).Value = dwData["LRFFLOTVH8"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR9", OracleType.NVarChar).Value = dwData["LRFFAKTOR9"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH9", OracleType.NVarChar).Value = dwData["LRFFLOTVH9"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR10", OracleType.NVarChar).Value = dwData["LRFFAKTOR10"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH10", OracleType.NVarChar).Value = dwData["LRFFLOTVH10"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR11", OracleType.NVarChar).Value = dwData["LRFFAKTOR11"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH11", OracleType.NVarChar).Value = dwData["LRFFLOTVH11"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR12", OracleType.NVarChar).Value = dwData["LRFFAKTOR12"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH12", OracleType.NVarChar).Value = dwData["LRFFLOTVH12"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR13", OracleType.NVarChar).Value = dwData["LRFFAKTOR13"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH13", OracleType.NVarChar).Value = dwData["LRFFLOTVH13"].ToString(); 
          or1.Parameters.Add("LRFFAKTOR14", OracleType.NVarChar).Value = dwData["LRFFAKTOR14"].ToString(); 
          or1.Parameters.Add("LRFFLOTVH14", OracleType.NVarChar).Value = dwData["LRFFLOTVH14"].ToString(); 
          or1.Parameters.Add("LRFFILLER", OracleType.NVarChar).Value = dwData["LRFFILLER"].ToString(); 
          or1.Parameters.Add("LRFAENDZL", OracleType.NVarChar).Value = dwData["LRFAENDZL"].ToString(); 
          or1.Parameters.Add("LRFAENDBEN", OracleType.NVarChar).Value = dwData["LRFAENDBEN"].ToString(); 
          or1.Parameters.Add("LRFAENDDAT", OracleType.NVarChar).Value = dwData["LRFAENDDAT"].ToString(); 
          or1.Parameters.Add("LRFNEUBEN", OracleType.NVarChar).Value = dwData["LRFNEUBEN"].ToString(); 
          or1.Parameters.Add("LRFNEUDAT", OracleType.NVarChar).Value = dwData["LRFNEUDAT"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
